include config
MAIN_PATH := /home/wangwei/dm365/dvsdk_dm365/filesystem/dm365rootfs/home/root
INCLUDE := include
LINUX_LIB := -lrt -lm
LIB := lib
libs := libpoweron.a libtest.a librun_ctrl.a libramps.a libflow.a libexception.a libstatmon.a libdisplay.a libsigpath.a libopsys.a libmath.a libglbram.a libmyfunc.a libdet.a libenglish.a libclktbl.a libmethod.a libdig_path.a libhostcmd.a libsocket.a libTUI.a libconfigs.a libuart.a

obj := main
#----------------------------------------------------------------------------
mylibs1 := $(subst .a,,$(subst lib,-l,$(libs)))
mylibs2 := $(subst lib,lib/lib,$(libs))
cleansub:= $(subst .a,.d,$(subst lib,,$(libs)))
$(obj):$(obj).c lib/liball.a
	$(CC) $(obj).c -o $(obj) -I $(INCLUDE) -L $(LIB) -lall $(LINUX_LIB)
	-rm lib/*.a
	cp $(obj) $(MAIN_PATH)

#--The dependences between librarys are confused. So we decompress every library to objects 
#--and compress *.o to liball.a. Then there is only one library(liball.a).
lib/liball.a:$(mylibs2)
	ar rcs lib/liball.a lib/*.o
	rm lib/*.o
$(mylibs2):
	cd $(subst .a,,$(subst $(LIB)/lib,,$@)) && make
	cp $(subst .a,,$(subst $(LIB)/lib,,$@))/$(subst lib/,,$@) $(LIB)
	cd lib && ar -x $(subst lib/,,$@)

.PHONY:clean
clean:$(cleansub)
	-rm -f $(obj) *.o *.d
	-rm -f $(LIB)/*.a $(LIB)/*.o
$(cleansub):
	cd $(subst .d,,$@) && make clean
